import { pageStore } from '@/pages/editor/store/page';
import { LcDocument } from '@/types/modules/editor/types/editor.type';

import { IPublicTypeRootSchema } from '@alilc/lowcode-types';
import { ITypeEntity } from '@/types/modules/superType/types';
import { getFileInfoFromPath } from '../../utils/getFileInfoFromPath';

export const createDefaultFile = function (path: string) {
  const { type, name, desc, folder } = getFileInfoFromPath(path);
  const splits = path.split('/');
  const fileName = splits[splits.length - 1];
  const isDocument = path?.endsWith('.tsx');
  if (isDocument) {
    let schema: IPublicTypeRootSchema = {
      componentName: 'Page',
      fileName,
      title: desc,
      meta: {
        title: desc,
        folder,
      },
    };
    const document: LcDocument = {
      types: [],
      projectId: pageStore.currentProjectId,
      type: 'Page',
      fileName: name,
      title: desc,
      schema,
      folder,
      width: pageStore.currentFrame === 'app' ? 375 : 1400,
      frames: [pageStore.currentFrame],
    };
    return document;
  } else {
    const typeEntity: ITypeEntity = {
      type,
      name,
      desc: desc || name,
      source: '',
    };
    return typeEntity;
  }
};
